#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include "rngs.h"

#define DEBUG 0

int checkAdventurer(struct gameState *post, int p){
struct gameState pre;
memcpy (&pre, post, sizeof(struct gameState));

   int cardDrawn;
int adventurerEffect;
int result;
int errors = 0;
int i;
   
result = cardEffect(adventurerEffect, 0,0,0, post, 0, 0);


for(i = 0; i < pre.handCount[p]; i++){
	drawCard(p, &pre);
	cardDrawn = pre.hand[p][pre.handCount[p]-1];

	if (cardDrawn != copper || cardDrawn != silver || cardDrawn != gold) {	
		pre.handCount[p]--; }}
assert (result == -1);
if(pre.handCount[p] != post->handCount[p]) {
	if(DEBUG)
	printf("Test Failed.\n");	
	errors++;
}

return errors;
}

int main() {
int i, n, p;
int errors = 0; 
struct gameState G;
   
printf ("Testing AdventureCard.\n");
SelectStream(2);
PutSeed(3);
for (n = 0; n < 2000; n++) {
for (i = 0; i < sizeof(struct gameState); i++) {
((char*)&G)[i] = floor(Random() * 256);
}
p = floor(Random() * 2);
G.deckCount[p] = floor(Random() * MAX_DECK);
G.discardCount[p] = floor(Random() * MAX_DECK);
G.handCount[p] = floor(Random() * MAX_HAND);
G.whoseTurn = p;

for (i = 0; i < G.deckCount[p]; i++) {
G.deck[p][i] = floor(Random() * treasure_map);
}
for (i = 0; i < G.discardCount[p]; i++) {
G.discard[p][i] = floor(Random() * treasure_map);
}
for (i = 0; i < G.handCount[p]; i++) {
G.hand[p][i] = floor(Random() * treasure_map);
}

errors += checkAdventurer(&G, p);}

if(errors)
printf("The number of  Errors found: %d\n", errors);
else
printf ("ALL TESTS OK\n");

return 0;
}